package com.wehealth.electrocardiograph_two_client.utils;

import android.annotation.SuppressLint;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
@SuppressLint("SimpleDateFormat")
public class FileUtils {

    /***
     * 像文件中写入数据 修改主从模式的时候使用
     * @param fileName
     * @param buffer
     * @return
     */
    public static int writeContentToFile(String fileName, char[] buffer) {
        int i = -1;
        try {
            File file = new File(fileName);
            if (!file.exists()) {
                if (!file.getParentFile().exists()) {
                    file.getParentFile().mkdirs();
                }
                file.createNewFile();
            }
            FileWriter fileWriter = new FileWriter(fileName);
            fileWriter.write(buffer);
            fileWriter.close();
            i = 0;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return i;
    }

 }
